//增加tag js
// tag 是一个JSON对象{id,tagName,module}
function newTag(tag){
	var id,tagName,module;
	id = tag.id;
	tagName = tag.tagName;
	module = tag.module;
	
	var html="";
	html += '<tr class="tagClass" id="tagTr'+id+'">';
	html += '<td id="tagNameTd'+id+'">'+tagName+'</td>';
	html += '<td>';
	html += '<a href="javascript:void(0)" title="'+__FMT.tagDetail_rename+'" onclick="renameTag('+id+')" class="rename"></a>&nbsp;';
	html += '<a href="javascript:void(0)" title="'+__FMT.tagDetail_delete+'" onclick="deleteTag('+id+')" class="del"></a>';
	html += '</td>';
	
	//start:hidden
	html += '<input type="hidden" name="tagId" id="tagId'+id+'" value="'+id+'"/>';
	//end:hidden
	html += '</tr>';
	$j('#tagListTable').append(html);
}
//删除标签
function deleteTag(tagId){
	if(confirm(__FMT.tagDetail_delete_confirm)){
		var postData = $j('#tagTr'+tagId+' :input').serialize();
		var url = __ctxPath+"/other/tag.html?doAction=delete";
		$j.post(url,postData,deleteTagCallback,"json");
	}
}
//删除标签callback
function deleteTagCallback(data){
	if(data.error && data.error!=""){
		alert(data.error);
		return ;
	}
	$j('#tagTr'+data.tagId).remove();
}
//重命名标签
function renameTag(tagId,inTagName){
	var tagName = window.prompt(__FMT.tagDetail_inputTagName,(inTagName!=null)?inTagName:$j('#tagNameTd'+tagId).html()); 
	if(tagName == null){
		return;
	}
	if(tagName==""){
		alert(__FMT.tagDetail_tagName_notNull);
		renameTag(tagId);
		return;
	}	
	if(tagName.length >= 30){
		alert(__FMT.tagDetail_tagName_tooLong);
		renameTag(tagId,tagName);
		return;
	}
	var postData ={"tagId":tagId,"tagName":tagName,"module":$('module').value};
	var url = __ctxPath+"/other/tag.html?doAction=rename";
	$j.post(url,postData,renameTagCallback,"json");
}
//重命名标签callback
function renameTagCallback(data){
	if(data.error && data.error!=""){
		alert(data.error);
		return ;
	}
	$j('#tagNameTd'+data.tagId).html(data.tagName);
}

//增加标签
function addTag(inTagName){
	var tagName = window.prompt(__FMT.tagDetail_inputTagName,(inTagName!=null)?inTagName:""); 
	if(tagName == null){
		return;
	}
	if(tagName==""){
		alert(__FMT.tagDetail_tagName_notNull);
		addTag();
		return;
	}	
	if(tagName.length >= 30){
		alert(__FMT.tagDetail_tagName_tooLong);
		addTag(tagName);
		return;
	}
	var url = __ctxPath+"/other/tag.html?doAction=add";
	var postData ={"tagName":tagName,"module":$('module').value};
	$j.post(url,postData,addTagCallback,"json");
}
//增加标签callback
function addTagCallback(data){
	if(data.error && data.error!=""){
		alert(data.error);
		return ;
	}
	newTag({id:data.tagId,tagName:data.tagName,module:data.module});
}

